﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SQLite;
using System.IO;
using System.Data;
using System.Data.Common;

namespace DIT.DB.Database
{
    internal class SLiteDatabase : DatabaseBase
    {
        public SLiteDatabase(string dataSource, string password, string startupScriptPath)
            : base(dataSource, null, password, startupScriptPath)
        {
            Setup();
        }

        private readonly string connectionStringFormat_Basic = "Data Source={0};Version=3;";
        private readonly string connectionStringFormat_Password = "Data Source={0};Version=3;Password={1};";

        protected override IDbConnection CreateConnection()
        {
            return new SQLiteConnection(ConnectionString);
        }

        protected override string ConnectionString
        {
            get
            {
                return string.IsNullOrWhiteSpace(password)
                           ? string.Format(connectionStringFormat_Basic, dataSource)
                           : string.Format(connectionStringFormat_Password, dataSource, password);
            }
        }
    }
}
